package com.whc.category.controller;

import com.whc.category.domain.entity.Category;
import com.whc.category.service.CategoryService;

import com.whc.common.domain.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/client/category")
@Slf4j
@Api(tags = "分类管理")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    @ApiOperation("查询所有分类")
    @GetMapping("/selectAll")
    public Result<List<Category>> selectAll(){
        List<Category> categories = categoryService.selectAll();
        return Result.success(categories);
    }

    @ApiOperation("根据id查询")
    @GetMapping("/selectOne")
    public Result<Category> selectOne(@RequestParam("id") Long id){
        Category category = categoryService.selectOne(id);
        return Result.success(category);
    }

    @ApiOperation("修改分类")
    @PostMapping("/update")
    public Result update(@RequestBody Category category){
        categoryService.update(category);
        return Result.success();
    }
    @ApiOperation("添加分类")
    @PostMapping("/add")
    public Result add(@RequestParam("CategoryName")String CategoryName){
        categoryService.add(CategoryName);
        return Result.success();
    }
    @ApiOperation("删除分类")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id){
        categoryService.delete(id);
        return Result.success();
    }
}
